// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    const {_id} = event
    console.log(event, _id)
    return await db.collection('books').where({
      _id
    })
      .update({
        data: {
          count: _.inc(1)
        }
      })
  } catch (err) {
    console.error(err)
  }
}